package day05;

import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/5
 */
public class getScore {
    /*
        评委打分：
            有6个评委打分，分数为1-100的整数。
            最后得分规则：去掉最高分和最低分，剩下的4个评委打分的平均值（不考虑小数部分）。
     */
    public static void main(String[] args) {
        int[] arr = new int[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个评委打分(1-100)：");
            int score = sc.nextInt();
            if (score < 1 || score > 100) {
                System.out.println("您输入的分数有误.");
                i--;
            } else {
                arr[i] = score;
            }
        }
        System.out.println("6位评委打分情况如下：");
        printArray(arr);
        System.out.println("--------------------");
        int max = getMax(arr);
        int min = getMin(arr);
        int sum = getSum(arr);
        int average = (sum - max - min) / (arr.length - 2);
        System.out.println("score:" + average);
    }

    private static int getSum(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    private static int getMax(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }
    private static int getMin(int[] arr) {
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        return min;
    }

    private static void printArray(int[] arr) {
        System.out.print("{");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length-1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ", ");
            }
        }
        System.out.println("}");
    }
}
